/**
 *******************************************************************************
 * @FileName  : flash.c
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 */

#include "flash.h"
#include "utils/track.h"
#include "utils/soft_uart.h"
#include "app_config.h"

#include "platform/platform.h"

#define USER_DATA_ADDR     0x76000

void FLASH_SetUp(void)
{
	delay_ms(10);

	TRACK("===========================\n");

	/* Erase 4K sector. */
	TRACK("FLash erase start... \nErase address: 0x%04X\n", USER_DATA_ADDR);
	FLASH_EraseSector(USER_DATA_ADDR);
	TRACK("FLash erase ok...\n\n");

	/* Write data to flash sector. */
	TRACK("FLash write start... \nWrite address: 0x%04X\nData Written: ", USER_DATA_ADDR);
	uint8_t dat[] ={0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC};
	TRACK_DATA(dat, sizeof(dat));
	FLASH_WritePage(USER_DATA_ADDR, dat, sizeof(dat));
	TRACK("FLash write ok...\n\n");


	/* Read data from flash sector. */
	TRACK("FLash read start... \nRead address: 0x%04X\nData Read: ", USER_DATA_ADDR);
	uint8_t cpy[100]={0};
	FLASH_ReadPage(USER_DATA_ADDR, cpy, sizeof(dat));
	TRACK_DATA(cpy, sizeof(dat));
	TRACK("FLash read ok...\n\n");
}

void FLASH_Loop(void)
{
}
